<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of classifypairs2</title>
  <meta name="keywords" content="classifypairs2">
  <meta name="description" content="Classify the bond pair by calculating change in energy if swapped">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">Code</a> &gt; classifypairs2.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for Code&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>classifypairs2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Classify the bond pair by calculating change in energy if swapped</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [pairs,currentEnergy]=classifypairs2(state,energyMatrix,moves,ne,pts) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">Classify the bond pair by calculating change in energy if swapped
For each neighboring pair, stores the change in energy if move is allowed
The energy is stored in a stacks of the original lattice site matrix
Each potential move is a stack containing the change in energy for the
move. pairs is the resultant set of stacks (currently there are 5
potential moves. The pair to the right, the pair down, two diagonals, and
flipping state
[pairs,currentEnergy]=classifypairs2(state,energyMatrix,moves,ne,pts)</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="neighbors2d.html" class="code" title="function n=neighbors2d(i,j,rows,columns)">neighbors2d</a>	neighbors2d creates a matrix whose entries return a vector of nearest</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="LatticeSimulation.html" class="code" title="function [s,cs,LL,F,Energy]=LatticeSimulation(varargin)">LatticeSimulation</a>	Lattice Simulation Model main routine</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function Ediff=findEnergyDifference(p1,p2,newp1,newp2)</a></li><li><a href="#_sub2" class="code">function Ediff=findEnergyDifference1(p1,newp1)</a></li></ul>

<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [pairs,currentEnergy]=classifypairs2(state,energyMatrix,moves,ne,pts)</a>
0002 <span class="comment">%Classify the bond pair by calculating change in energy if swapped</span>
0003 <span class="comment">%For each neighboring pair, stores the change in energy if move is allowed</span>
0004 <span class="comment">%The energy is stored in a stacks of the original lattice site matrix</span>
0005 <span class="comment">%Each potential move is a stack containing the change in energy for the</span>
0006 <span class="comment">%move. pairs is the resultant set of stacks (currently there are 5</span>
0007 <span class="comment">%potential moves. The pair to the right, the pair down, two diagonals, and</span>
0008 <span class="comment">%flipping state</span>
0009 <span class="comment">%[pairs,currentEnergy]=classifypairs2(state,energyMatrix,moves,ne,pts)</span>
0010 
0011 <span class="comment">%pairs stores energy for swaping sites</span>
0012 <span class="comment">%not swappable value to use</span>
0013 nomove=-250;
0014 
0015 <span class="keyword">global</span> pairsMap
0016 <span class="comment">%flips stores energy difference for allowed flips</span>
0017 
0018 s=state;
0019 
0020 <span class="comment">%rescale=[1 2 6];</span>
0021 <span class="comment">%rescaleS=rescale(s);</span>
0022 
0023 <span class="comment">% nStates=length(stateValues);</span>
0024 <span class="comment">% logicalIndex=false([size(s) nStates]);</span>
0025 <span class="comment">% for istate=1:nStates</span>
0026 <span class="comment">%     logicalIndex(:,:,istate)=(s==stateValues(istate));</span>
0027 <span class="comment">% end</span>
0028 <span class="comment">% for istate=1:nStates</span>
0029 <span class="comment">%     s(logicalIndex(:,:,istate))=istate;</span>
0030 <span class="comment">% end</span>
0031 et=energyMatrix;
0032 [rows,cols]=size(s);
0033 
0034 <span class="keyword">if</span> nargin&lt;4
0035     ne=zeros(8,rows,cols);
0036     <span class="keyword">for</span> i=1:rows
0037         <span class="keyword">for</span> j=1:cols
0038             ne(:,i,j)=<a href="neighbors2d.html" class="code" title="function n=neighbors2d(i,j,rows,columns)">neighbors2d</a>(i,j,rows,cols);
0039         <span class="keyword">end</span>
0040     <span class="keyword">end</span>
0041 <span class="keyword">end</span>
0042 <span class="keyword">if</span> nargin&lt;5
0043     doFull=true;
0044     pts=1:rows*cols;
0045 <span class="keyword">else</span>
0046     doFull=false;
0047 <span class="keyword">end</span>
0048 
0049 
0050 pairs=zeros(5,rows,cols);
0051 
0052 currentEnergy=0;
0053 
0054 <span class="keyword">for</span> kk=1:length(pts)
0055     pts1=ne([2 4 5 6],pts(kk));
0056         <span class="keyword">if</span> s(pts(kk))==1 || s(pts(kk))==4 || s(pts(kk))==5
0057             pairs(5,pts(kk))=nomove;
0058         <span class="keyword">end</span>
0059         <span class="comment">%originaly flip individual</span>
0060         <span class="comment">%if s(pts(kk))==2</span>
0061         <span class="comment">%change to only flip attached</span>
0062         <span class="keyword">if</span> s(pts(kk))==2 &amp;&amp; any(s(ne(1:4,pts(kk)))==3)
0063              pairs(5,pts(kk))=<a href="#_sub2" class="code" title="subfunction Ediff=findEnergyDifference1(p1,newp1)">findEnergyDifference1</a>(pts(kk),3);
0064         <span class="keyword">else</span>
0065             pairs(5,pts(kk))=nomove;
0066         <span class="keyword">end</span>
0067          <span class="keyword">if</span> s(pts(kk))==3
0068                pairs(5,pts(kk))=<a href="#_sub2" class="code" title="subfunction Ediff=findEnergyDifference1(p1,newp1)">findEnergyDifference1</a>(pts(kk),2);
0069          <span class="keyword">end</span>
0070     <span class="keyword">for</span> cnt=1:length(pts1)
0071 <span class="comment">%         pairs(cnt+4,pts(kk))=nomove;</span>
0072 <span class="comment">%         pairs(cnt+8,pts(kk))=nomove;</span>
0073 
0074        
0075         
0076     <span class="keyword">if</span> s(pts(kk))==s(pts1(cnt))  || s(pts(kk))==4 || s(pts1(cnt))==4 <span class="keyword">...</span>
0077             || (s(pts(kk))==5 &amp;&amp; s(pts1(cnt))==1) || <span class="keyword">...</span>
0078             (s(pts(kk))==1 &amp;&amp; s(pts1(cnt))==5) || <span class="keyword">...</span>
0079             s(pts(kk))==3 || s(pts1(cnt))==3
0080         
0081            pairs(cnt,pts(kk))=nomove;
0082     <span class="keyword">else</span>
0083         pairs(cnt,pts(kk))=<a href="#_sub1" class="code" title="subfunction Ediff=findEnergyDifference(p1,p2,newp1,newp2)">findEnergyDifference</a>(pts(kk),pts1(cnt),s(pts1(cnt)),s(pts(kk)));
0084             
0085     <span class="keyword">end</span>
0086     <span class="keyword">if</span> cnt&lt;3
0087      <span class="keyword">if</span> s(pts(kk))==2 &amp;&amp; s(pts1(cnt))==2
0088         pairs(cnt,pts(kk))=<a href="#_sub1" class="code" title="subfunction Ediff=findEnergyDifference(p1,p2,newp1,newp2)">findEnergyDifference</a>(pts(kk),pts1(cnt),3,3);
0089      <span class="keyword">end</span>
0090     <span class="keyword">end</span>
0091     <span class="keyword">end</span>
0092         
0093 
0094        
0095         <span class="keyword">if</span> doFull
0096             currentEnergy=currentEnergy-et(s(pts(kk)),s(pts1(1)))-et(s(pts(kk)),s(pts1(2)));
0097         <span class="keyword">end</span>
0098    
0099 <span class="keyword">end</span>
0100 <a name="_sub1" href="#_subfunctions" class="code">function Ediff=findEnergyDifference(p1,p2,newp1,newp2)</a>
0101 oldp1=s(p1);
0102 oldp2=s(p2);
0103 
0104 
0105 <span class="keyword">if</span> (pairsMap(oldp1,oldp2,s(ne(1,p1)),s(ne(2,p1)),s(ne(3,p1)),s(ne(4,p1)),s(ne(1,p2)),s(ne(2,p2)),s(ne(3,p2)),s(ne(4,p2)),newp1,newp2)&gt;-500)
0106     Ediff=pairsMap(oldp1,oldp2,s(ne(1,p1)),s(ne(2,p1)),s(ne(3,p1)),s(ne(4,p1)),s(ne(1,p2)),s(ne(2,p2)),s(ne(3,p2)),s(ne(4,p2)),newp1,newp2);
0107 <span class="keyword">else</span>
0108     e11=sum(et(s(p1),s(ne(1:4,p1))));
0109     e12=sum(et(s(p2),s(ne(1:4,p2))));
0110     e11=e11-et(oldp1,oldp2);
0111             <span class="comment">%Swap</span>
0112             s(p1)=newp1;
0113             s(p2)=newp2;
0114             <span class="comment">%Energy After swap</span>
0115     e21=sum(et(s(p1),s(ne(1:4,p1))));
0116     e22=sum(et(s(p2),s(ne(1:4,p2))));
0117     e22=e22-et(newp1,newp2);
0118             Ediff=-(e21+e22-e11-e12);
0119             <span class="comment">%Swap Back for further calculations</span>
0120             
0121     s(p1)=oldp1;
0122     s(p2)=oldp2;
0123     pairsMap(oldp1,oldp2,s(ne(1,p1)),s(ne(2,p1)),s(ne(3,p1)),s(ne(4,p1)),s(ne(1,p2)),s(ne(2,p2)),s(ne(3,p2)),s(ne(4,p2)),newp1,newp2)=Ediff;
0124 <span class="keyword">end</span>
0125 <span class="keyword">end</span>
0126 <a name="_sub2" href="#_subfunctions" class="code">function Ediff=findEnergyDifference1(p1,newp1)</a>
0127 oldp1=s(p1);
0128 e21=0;
0129 e11=sum(et(s(p1),s(ne(1:4,p1))));
0130 
0131             <span class="comment">%Swap</span>
0132             s(p1)=newp1;
0133             <span class="keyword">if</span> newp1==2
0134                 <span class="keyword">for</span> gi=1:4
0135                     <span class="keyword">if</span> s(ne(gi,p1))==3
0136                         
0137                         <span class="keyword">if</span> ~any(s(ne(1:4,ne(gi,p1)))==3)
0138                             e11=e11+sum(et(3,s(ne(1:4,ne(gi,p1)))));
0139                             <span class="comment">%s(ne(gi,p1))=2;</span>
0140                             e21=e21+sum(et(2,s(ne(1:4,ne(gi,p1)))));
0141                         <span class="keyword">end</span>
0142                     <span class="keyword">end</span>
0143                   
0144                 <span class="keyword">end</span>
0145             <span class="keyword">end</span>
0146            
0147             <span class="comment">%Energy After swap</span>
0148 e21=e21+sum(et(s(p1),s(ne(1:4,p1))));
0149 
0150             Ediff=-(e21-e11);
0151             <span class="comment">%Swap Back for further calculations</span>
0152             
0153 s(p1)=oldp1;
0154 
0155 
0156 <span class="keyword">end</span>
0157 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Mon 21-May-2012 09:54:18 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>